package com.maxchaintech.integral.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.maxchaintech.integral.domain.PointsRedemptionOrder;
import com.maxchaintech.integral.service.IPointsRedemptionOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.maxchaintech.common.log.annotation.Log;
import com.maxchaintech.common.log.enums.BusinessType;
import com.maxchaintech.common.security.annotation.PreAuthorize;
import com.maxchaintech.common.core.web.controller.BaseController;
import com.maxchaintech.common.core.web.domain.AjaxResult;
import com.maxchaintech.common.core.utils.poi.ExcelUtil;
import com.maxchaintech.common.core.web.page.TableDataInfo;

/**
 * 积分兑换订单Controller
 * 
 * @author jyw
 * @date 2021-04-20
 */
@RestController
@RequestMapping("/order")
public class PointsRedemptionOrderController extends BaseController
{
    @Autowired
    private IPointsRedemptionOrderService pointsRedemptionOrderService;

    /**
     * 查询积分兑换订单列表
     */
    @PreAuthorize(hasPermi = "integral:order:list")
    @GetMapping("/list")
    public TableDataInfo list(PointsRedemptionOrder pointsRedemptionOrder)
    {
        startPage();
        List<PointsRedemptionOrder> list = pointsRedemptionOrderService.selectPointsRedemptionOrderList(pointsRedemptionOrder);
        return getDataTable(list);
    }

    /**
     * 导出积分兑换订单列表
     */
    @PreAuthorize(hasPermi = "integral:order:export")
    @Log(title = "积分兑换订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PointsRedemptionOrder pointsRedemptionOrder) throws IOException
    {
        List<PointsRedemptionOrder> list = pointsRedemptionOrderService.selectPointsRedemptionOrderList(pointsRedemptionOrder);
        ExcelUtil<PointsRedemptionOrder> util = new ExcelUtil<PointsRedemptionOrder>(PointsRedemptionOrder.class);
        util.exportExcel(response, list, "积分兑换订单数据");
    }

    /**
     * 获取积分兑换订单详细信息
     */
    @PreAuthorize(hasPermi = "integral:order:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(pointsRedemptionOrderService.selectPointsRedemptionOrderById(id));
    }

    /**
     * 新增积分兑换订单
     */
    @PreAuthorize(hasPermi = "integral:order:add")
    @Log(title = "积分兑换订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PointsRedemptionOrder pointsRedemptionOrder)
    {
        return toAjax(pointsRedemptionOrderService.insertPointsRedemptionOrder(pointsRedemptionOrder));
    }

    /**
     * 修改积分兑换订单
     */
    @PreAuthorize(hasPermi = "integral:order:edit")
    @Log(title = "积分兑换订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PointsRedemptionOrder pointsRedemptionOrder)
    {
        return toAjax(pointsRedemptionOrderService.updatePointsRedemptionOrder(pointsRedemptionOrder));
    }

    /**
     * 删除积分兑换订单
     */
    @PreAuthorize(hasPermi = "integral:order:remove")
    @Log(title = "积分兑换订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pointsRedemptionOrderService.deletePointsRedemptionOrderByIds(ids));
    }
}
